.module m0
.pseg
.global _main
; TESTE uRISC - Tesde de Divisao
;
; Instrucoes que saltam para as rotinas de tratamento de
; de interrupcoes
j RESET
j INT1
j INT2
j INT3

;r0 dividendo
;r1 divisor
;r2 resto
;r4 quociente

; Inicio do programa
RESET: 
lcl r0, LOWBYTE 257  ; carrega r0
lch r0, HIGHBYTE 257 ;          
lcl r1, LOWBYTE 10  ; carrega r1
lch r1, HIGHBYTE 10 ;
lcl r6, LOWBYTE 32768 ; carrega r6
lch r6, HIGHBYTE 32768 

LOP1:
and r5, r0, r6
jf.zero FA
lsr r6, r6
j LOP1
FA:

passa r3,r1

LOP2:
and r5, r1, r6
jf.zero FB
lsl r1, r1
j LOP2
FB:

zeros r4
LOP3:
lsl r4, r4
sub r5, r0, r1
jt.neg DESLOCA
passa r0, r5
inca r4, r4
DESLOCA:
lsr r1, r1
sub r5, r1, r3
jf.neg LOP3

passa r2, r0

loadlit r6, 1000
store r6, r4      ;quociente

HALT: j HALT

INT1: jr r7
INT2: jr r7
INT3: jr r7
.end